package org.junzerg.Test;

import com.google.common.base.CharMatcher;
import com.google.common.base.Splitter;

import java.util.ArrayList;
import java.util.List;

import static com.google.common.base.CharMatcher.digit;

/**
 * Created by pengjunzhe on 2018/4/24.
 */
public class SplitterTest {
    public static void main(String[] args) {
        List<String> asd = new ArrayList<String>();
        asd.add("");

        String string = "a,,b1,    c,,,d";
        // 默认拆
        Iterable<String> result = Splitter.on(',').split(string);
        System.out.println(result);// [a, , b1,     c, , , d]
        // 拆之后去掉空的
        result = Splitter.on(',').omitEmptyStrings().split(string);
        System.out.println(result);// [a, b1,     c, d]
        // 拆之后去掉头尾空格
        result = Splitter.on(',').trimResults().split(string);
        System.out.println(result);// [a, , b1, c, , , d]
        // 拆之后去掉空的,还去掉空格
        result = Splitter.on(',').omitEmptyStrings().trimResults().split(string);
        System.out.println(result);// [a, b1, c, d]
        // 拆之后去掉数字
        result = Splitter.on(',').omitEmptyStrings().trimResults(CharMatcher.digit()).split(string);
        System.out.println(result);// [a, b,     c, d]
    }
}
